﻿using System.Linq;
using Complaint.Models.Dtos;

namespace Complaint.Repositories
{
    public class SettlementRepository : BaseRepository<Settlement>, IRepository<Settlement>
    {
        #region IRepository<Settlement> Members

        public void Create(Settlement dto)
        {
            ObjectContext.AddToSettlement(dto);
            Update(dto);
        }

        public IQueryable<Settlement> FindAll()
        {
            return ObjectContext.Settlement;
        }

        public Settlement FindById(int id)
        {
            return FindAll().FirstOrDefault(s => s.SettlementID == id);
        }

        public IQueryable<Settlement> FindByName(string name)
        {
            return from settlement in FindAll()
                   where settlement.Description.Contains(name)
                   select settlement;
        }

        #endregion

        public IQueryable<Settlement> FindByComplaint(int id)
        {
            return from settlement in FindAll()
                   where settlement.Complaint.ComplaintID == id
                   select settlement;
        }
    }
}